// 初始化 canvas 显示屏倍率
export default (id: string) => {
  const oCanvas = document.getElementById(id) as HTMLCanvasElement;
  const ctx = oCanvas.getContext('2d');
  const oldWidth = oCanvas.width;
  const oldHeight = oCanvas.height;

  if (ctx) {
    const { devicePixelRatio } = window;
    const dpr = devicePixelRatio || 1;
    oCanvas.width = Math.round(oldWidth * dpr);
    oCanvas.height = Math.round(oldHeight * dpr);
    oCanvas.style.width = oldWidth + 'px';
    oCanvas.style.height = oldHeight + 'px';
    ctx.scale(dpr, dpr);
    return dpr;
  }
  return 1;
};